Skip to main content
Time to complete: 20-30 minutes The Sequence Transactions API can be implemented on a serverless Cloudflare worker so a game or app user interaction is seamless without a confirmation signature or gas payment. You’ll also benefit from not having to be worried about transaction speed, throughput and re-orgs by the relayer, and experience automatic scaling with Cloudflare. The following steps will guide you through how to build your hosted minter API in 4 steps:
  1. Setup Cloudflare Environment with Wrangler Cli and Deploy a Test
  2. Deploy, Sponsor & Update Metadata for an ERC1155 Contract with Sequence Builder
  3. Use EthAuthProof to Prevent EOA DDoS
  4. Mint a Collectible to Wallet
The result, a secure API with the following specs:
  • HTTPS GET: returns blockNumber
  • HTTPS POST(proof, address): mints a collectible & returns transaction hash
You need basic knowledge of wrangler cli, npm, and Sequence Builder in order to complete this implementation.

1. Setup Cloudflare Environment With Wrangler Cli and Deploy a Test

In order to create the project from scratch, first create a project with mkdir, cd into the project, and run pnpm init to create a package.json. Next, make sure wrangler cli is installed in your project and set the wrangler keyword as an alias in your local bash session.
Create an account on the Cloudflare site and perform a login step to login to your Cloudflare dashboard to connect the Cloudflare platform to your local development environment.
Once logged in, initialize the project in the directory by accepting one of the randomly generated project folder names provided that you like, and follow the prompts to initialize your git tracked typescript "Hello World" Worker application.
To complete this step, you should press enter 4 times after wrangler init with the last 2 step answered as No to decline git versioning and deployment. This will clone down a starter repository that can be used to deploy code to the cloud.
Local API Testing
At any point in the guide, you can use the wrangler dev command in the project folder for local testing

Deploy Test

Finally, cd into the randomly generated project folder, and perform a wrangler deploy command. This should print a URL, which you can enter in the browser the URL https://<app>.<account>.workers.dev to view the Hello World! result.

2. Deploy, Sponsor and Update Metadata for an ERC1155 Contract with Sequence Builder

To use the Transactions API, you’ll need to upgrade your Billing to Developer for your project in Sequence Builder which can be with this walkthrough
First, follow this guide to deploy a contract. Then, one must update the role access of the contract in the Builder to only receive requests from the minter wallet address, which can be done in 2 steps. You can do this in Sequence Builder by providing minter permission to your Sequence Wallet Transactions API Address. In order to know what the transactions API address you are working with is, one must first either:
  1. Have one generated for you using this app by selecting your network, and generating a wallet key with the generate local wallet button (for demo purposes only)
  2. Recommended: You can also print locally the account address produced from an EOA wallet private key using the following code snippet:
To do so, open your project, navigate to the Contracts page, select your Linked contracts and under Write Contract tab expand the grantRole method. Complete with the following details: bytes32 role: 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6 address account: <Generated Sequence Transactions API Wallet Address>
Grant a role for the relayer
Where the role string inputted is the result of keccak256("MINTER_ROLE") in solidity or ethers.keccak256(ethers.toUtf8Bytes("MINTER_ROLE")) in javascript This makes it so that only your specific address can mint from the contract, it will error otherwise. Complete the role update by clicking write and sign the sponsored transaction.

Update Metadata

Next, you’ll need to update the metadata with your media or assets for your contract, which can be done by following this guide.

Contract Sponsoring

Finally, in order to sponsor the contract follow this guide to sponsor a contract.

3. Use EthAuthProof to prevent EOA DDoS

Now that we have a contract deployed, we can return to the cloudflare worker directory and project, and install ethers and 0xsequence to get access to sequence APIs in order to perform a proof validation that the request is coming from a trusted source, a sequence wallet.
Then, we have to add a type of middleware, after we check if it’s a POST or GET request. If it’s a POST request, verify that the passed in proofString and address are valid, as well as the environment variables. The code scaffold placed into src/index.ts would look like this, with callContract and getBlockNumber mocked out, using the mentioned verification step of calling verify before any contract call.

Add Cloudflare Environment Variables

Then, pass in the environment variables for your build by updating the [vars] section in your wrangler.toml.

Implement Window Object in Wrangler Template

It should be noted, if you try to deploy this you’ll get a missing window object required by the web3 modules. To prevent this, add the following line to your wrangler.toml file to make the environment compatible.

Testing the Deploy

You can now redeploy using wrangler deploy And perform a curl request to test your endpoint like such:
You can acquire your wallet address proof by using this dapp and follow the below steps.

Using the ETHAuthProof Viewer dapp

When you arrive on the page, the first thing you should do is select a network. Then you have an option to either connect and generate the Proof, or, generate a local wallet
ETHAuthProof Viewer
Press the connect button and then copy to clipboard.
ETHAuthProof Viewer copy to clipboard
It should be noted, it is best not to share this ETHAuthProof with anyone as this means someone can prove ownership of your wallet and interact with specific APIs. Finally, replace the url with your app from this step, the <some_proof> with the generated value copied from the viewer app, and <some_address> with your wallet address and it should return just the mocked 0x string.

4. Mint a Collectible to Wallet

Finally, to deploy and mint a collectible from the sponsored contract address, we install the following packages
and implement the callContract and getBlockNumber methods previously mocked out as follows:
Once these steps are complete, you can redeploy and test with the steps outlined in this prior step, and this time the POST request should return a transaction hash for the completed mint and the GET request would return a block number. If you want to browse the full code, see an example implementation here